# The guess API is already defined for you.
# @param num, your guess
# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
# def guess(num):


class Solution(object):
    def guessNumber(self, n):
        """
        :type n: int
        :rtype: int
        """
        min_num, max_num = 0, n + 1
        while True:
            mid = (min_num + max_num) // 2
            res = guess(mid)
            if res == 0:
                return mid
            elif res == -1:
                max_num = mid
            else:
                min_num = mid
